package work.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import work.entity.User;
import work.repository.UserRepository;
import work.service.UserService;

import java.util.List;

@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private UserRepository userRepository;

    @Override
    public User findById(String id) {
        return userRepository.findById(id);
    }

    @Override
    public int register(User user) {
        return userRepository.register(user);
    }

    @Override
    public int updatePassword(User user) {
        return userRepository.updatePassword(user);
    }

    @Override
    public User verify(User user) {
        return userRepository.verify(user);
    }

    @Override
    public List<User> findUsers(User user) {
        if (user.getUserId() != null && user.getUserId() != "") {
            String s = "%" + user.getUserId() + "%";
            user.setUserId(s);
        }

        if (user.getUserName() != null && user.getUserName() != "") {
            String s = "%" + user.getUserName() + "%";
            user.setUserName(s);
        }

        return userRepository.findUsers(user);
    }

    @Override
    public List<User> findWorkers(User user) {
        user.setUserId("%" + user.getUserId() + "%");
        user.setUserName("%" + user.getUserName() + "%");
        return userRepository.findWorkers(user);
    }

    @Override
    public int updateStatus(User user) {
        return userRepository.updateStatus(user);
    }

    @Override
    public int deleteWorker(User user) {
        return userRepository.deleteWorker(user);
    }
}
